/*
 * DocumentMenu.java
 * Describe SWF
 *
 * A browser for Flash files.
 * Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307 USA
 * 
 * For more information please contact:
 * 
 * Stuart MacKay
 * Flagstone Software Ltd
 * 92 High Street
 * Wick, Caithness KW1 4LY
 * Scotland
 * 
 * www.flagstonesoftware.com
 */
package com.flagstone.describe;

import javax.swing.*;
import java.awt.event.*;

class DocumentMenu extends JMenuBar
{
    private static final long serialVersionUID = 0;
    private static final int COMMAND_MASK;

    static 
    {
        COMMAND_MASK = App.getInstance().isWindows() ? KeyEvent.CTRL_MASK : KeyEvent.META_MASK;
    }
    
    Document owner;
    
    JMenuItem export = null;
    
    DocumentMenu(Document aDocument)
    {
        owner = aDocument;
        
        JMenu fileMenu = new JMenu("File");
        
        export = new JMenuItem(new ExportAction());
        export.setEnabled(false);

        fileMenu.add(new JMenuItem(new OpenAction()));
        fileMenu.addSeparator();
        fileMenu.add(export);
        fileMenu.addSeparator();
        fileMenu.add(new JMenuItem(new CloseAction()));
        fileMenu.addSeparator();
        fileMenu.add(new JMenuItem(new QuitAction()));
        
        this.add(fileMenu);
    }
    
    void enableExport(boolean enable)
    {
        export.setEnabled(enable);
    }
    
    private class OpenAction extends AbstractAction implements ActionListener 
    {
        private static final long serialVersionUID = 0;

        public OpenAction() 
        {
            super(App.getInstance().localizedString("FileMenu.Open"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, COMMAND_MASK));
        }
        public void actionPerformed(ActionEvent ae) 
        {
            owner.open();
        }
    }
    private class ExportAction extends AbstractAction implements ActionListener 
    {
        private static final long serialVersionUID = 0;

        public ExportAction() 
        {
            super(App.getInstance().localizedString("FileMenu.Export"));
        }
        public void actionPerformed(ActionEvent ae) 
        {
            owner.export();
        }
    }
    private class CloseAction extends AbstractAction implements ActionListener 
    {
        private static final long serialVersionUID = 0;

        public CloseAction() 
        {
            super(App.getInstance().localizedString("FileMenu.Close"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W, COMMAND_MASK));
        }
        public void actionPerformed(ActionEvent ae) 
        {
            owner.close();
        }
    }
    private class QuitAction extends AbstractAction implements ActionListener 
    {
        private static final long serialVersionUID = 0;

        public QuitAction() 
        {
            super(App.getInstance().localizedString("FileMenu.Quit"));
            putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, COMMAND_MASK));
        }
        public void actionPerformed(ActionEvent ae) 
        {
            owner.quit();
        }
    }
}
